package com.kaisheng.service;

import java.util.List;

import com.kaisheng.dao.FilesDao;
import com.kaisheng.entity.Files;
import com.kaisheng.util.PKUtil;
import com.kaisheng.util.TimeUtil;

public class FilesService {
	FilesDao fd = new FilesDao();
	public List<Files> findByProjectId(String project_id) {
		
		return fd.findByProjectId(project_id);
	}
	public void save(String name, String user_id, String project_id) {
		Files files = new Files();
		files.setId(PKUtil.getId());
		files.setName(name);
		files.setProject_id(project_id);
		files.setUser_id(user_id);
		files.setCreatetime(TimeUtil.getTime());
		fd.save(files);
		
		
	}
	public void update(String files_id,String filesize,int n) {
		Files files = new Files();
		files = fd.findByFilesId(files_id);
		long si = Long.parseLong(files.getSize());
		long s = Long.parseLong(filesize);
		if(n>0){
			si = si+s;
		}else{
			si = si-s;
		}
		String str = String.valueOf(si);
		fd.update(files,str,n);
		
	}
	public boolean del(String files_id) {
		return fd.del(files_id);
		
	}
	public Files findById(String filesId) {
		return fd.findByFilesId(filesId);
	}

}
